home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / wndwc20.zip / WNDWMGR.C < prev    next >
Text File  |  1989-03-06  |  12KB  |  352 lines

  1. /*===========================================================================*\
  2. | WNDWMGR.C - Multi-level virtual window demo               ver 2.0, 03-06-89 |
  3. |             to demonstrate powerful window management.                      |
  4. |                                                                             |
  5. |   This program shows you how the window management utilities allow you to   |
  6. | access any window at any time.  You can even hide the top level window for  |
  7. | displaying later.                                                           |
  8. |   The demo places a very heavy load on screen processing by doing full      |
  9. | screen scrolling on the virtual screens and then updating them on the CRT.  |
  10. | Notice that the full windows are updated even if covered.  The constantly   |
  11. | scrolling screens are there just to make it more apparent where and how     |
  12. | fast the windows are being updated.                                         |
  13. |   Run program.  Instructions are on the screen.                             |
  14. |                                                                             |
  15. | Be sure that you fully exit the program so that the keyboard interrupt      |
  16. | handler can be fully restored.  If you do not wish to use the keyboard      |
  17. | handler during debugging, change the value passed to setkbdhandler in main  |
  18. | to 0 rather than 1.                                                         |
  19. |   Copyright (c) 1989 by James H. LeMay,  All rights reserved.               |
  20. \*===========================================================================*/
  21.  
  22. #include <stdio.h>
  23. #include <conio.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <time.h>
  27. #include <process.h>
  28.  
  29. #include "qwikc20.h"
  30. #include "wndwc20.h"
  31. #include "keybc20.h"
  32.  
  33. /* ASCII key codes: */
  34. #define ALT1 120
  35. #define ALT2 121
  36. #define ALT3 122
  37. #define ALT4 123
  38. #define LEFTARROW 75
  39. #define RIGHTARROW 77
  40. #define UPARROW 72
  41. #define DOWNARROW 80
  42. #define HOMEKEY 71
  43. #define ENDKEY 79
  44. #define PGUP 73
  45. #define PGDN 81
  46. #define ESCKEY 27
  47. #define RETKEY 13
  48. #define F5KEY 63
  49. #define F10KEY 68
  50.  
  51. #define SCROLLLOCK 0x10
  52. #define MOVEMODE 0x01
  53. #define RESIZEMODE 0x02
  54. #define SCROLLMODE 0x04
  55.  
  56. unsigned char rowstep;
  57. unsigned char colstep;
  58. unsigned char i;
  59. unsigned char line;
  60. unsigned char fastrowstep;
  61. unsigned char fastcolstep;
  62. char altermode=MOVEMODE;
  63. int numofrows;
  64. int numofcols;
  65. int name;
  66. int key;
  67. char extkey;
  68. char typematic;
  69.  
  70. char stra[25][80]=
  71. { "╓──────────────────────────────────────────────────────────╖",
  72.   "╙─╥────────── E A G L E  Performance Software ───────────╥─╜",
  73.   "  ╙─╥───── P.O. Box 292786, Lewisville, TX  75029 ─────╥─╜",
  74.   "    ╙──────────────────────────────────────────────────╜",
  75.   "WNDWC20   gives  you  unparalleled  performance  in   window",
  76.   "software  for Turbo C 2.0.  It features fixed,  hidden,  and",
  77.   "true  virtual  windows with true  random-access.   Now  your",
  78.   "windows can be dynamically updated even if they are covered!",
  79.   "The  speed  of hidden and virtual screens is  phenomenal  as",
  80.   "they use the direct writing routines of QWIKC20.",
  81.   "",
  82.   "RANDOM  ACCESS  is the power to pull any window to  the  top",
  83.   "even if they are covered without shuffling!  This means your",
  84.   "windows can be in any order and not just stacked or tiled.",
  85.   "",
  86.   "VIRTUAL WINDOWS - The screens for virtual windows can be  of",
  87.   "any  row  and  column size in a 64k buffer.   The  rows  and",
  88.   "columns  can  range  from 1 to 255.  These  windows  can  be",
  89.   "resized, zoomed, or scrolled right on the screen!",
  90.   "",
  91.   "Programmers will find the code very easy to use and  simple.",
  92.   "All  the  hard working code is  kept  transparent.   Several",
  93.   "window-relative and window management routines are included.",
  94.   "",
  95.   "" };
  96.  
  97.  
  98. /*==============================| scrollon |================================*\
  99. Returns the Scroll Lock status (0=off, nonzero=on).
  100. \*==========================================================================*/
  101. int scrollon(void)
  102. {
  103.     return((*keystatus & SCROLLLOCK) != 0);
  104. }
  105.  
  106.  
  107. /*==========================| updatekeystatus |=============================*\
  108. \*==========================================================================*/
  109. void updatekeystatus(void)
  110. {
  111.     char s[20];
  112.  
  113.     if(scrollon()) {
  114.         if(!virtualflag) altermode=MOVEMODE;
  115.         qwrite( crt_rows, 61, WHITE+GREEN_BG,
  116.                 (sprintf( s, "%c%c%c%c", 24, 25, 27, 26 ), s) );
  117.         switch(altermode) {
  118.             case MOVEMODE:   strcpy( s, "-Move   " ); break;
  119.             case RESIZEMODE: strcpy( s, "-Resize " ); break;
  120.             case SCROLLMODE: strcpy( s, "-Scroll " ); break;
  121.         }
  122.         qwriteeos( BLACK+GREEN_BG, s );
  123.         qwriteeos( YELLOW+GREEN_BG, " SCROLL" );
  124.     } else {
  125.         qfill( crt_rows, 61, 1, 20, GREEN_BG, ' ' );
  126.     }
  127. }
  128.  
  129.  
  130. /*===========================| updatewindows |==============================*\
  131. For this demo, the windows are not only being scrolled on the screen,
  132. but also in RAM, whether they are seen or not!  So, let's give it a
  133. heavy CPU and video load, and see how fast it still can go.
  134. \*==========================================================================*/
  135. void updatewindows(void)
  136. {
  137.     writetovirtual(name);
  138.     wscrollup();          /* for the heaviest load, scroll up entire screen */
  139.     wwrite( 25, 2, stra[line] );   /* wrap a new line at the bottom */
  140.     vupdatewindow();
  141.  
  142.     if(++name==WINDOW4) {
  143.         name = WINDOW1;
  144.         if(line==24) line=0;
  145.         else ++line;
  146.     }
  147. }
  148.  
  149.  
  150. /*==============================| kbdidle |=================================*\
  151. Here's where the windows are updated!  When the keyboard is idle, the
  152. following function is run.  You may change the contents of course.
  153. \*==========================================================================*/
  154. void kbdidle(void)
  155. {
  156.     updatewindows();
  157.     writetocrt();
  158.     updatekeystatus();
  159. }
  160.  
  161.  
  162. /*===========================| initsteprates |==============================*\
  163. \*==========================================================================*/
  164. void initsteprates(void)
  165. {
  166.     if(crt_rows>40) fastrowstep=4;
  167.     else fastrowstep=2;
  168.     fastcolstep=crt_cols/20;
  169. }
  170.  
  171.  
  172. /*==========================| adjuststeprates |=============================*\
  173. \*==========================================================================*/
  174. void adjuststeprates(void)
  175. {
  176.     if(typematic) {
  177.         colstep=fastcolstep;
  178.         rowstep=fastrowstep;
  179.     } else {
  180.         colstep=1;
  181.         rowstep=1;
  182.     }
  183. }
  184.  
  185.  
  186. /*==============================| getsteps |================================*\
  187. \*==========================================================================*/
  188. void getsteps( int *numofrows, int *numofcols )
  189. {
  190.     int rows=0;
  191.     int cols=0;
  192.  
  193.     adjuststeprates();
  194.     switch(key) {
  195.         case UPARROW:    rows = -rowstep; break;
  196.         case DOWNARROW:  rows =  rowstep; break;
  197.         case LEFTARROW:  cols = -colstep; break;
  198.         case RIGHTARROW: cols =  colstep; break;
  199.         case PGUP:       rows = -255;     break;
  200.         case PGDN:       rows =  255;     break;
  201.         case HOMEKEY:    cols = -255;     break;
  202.         case ENDKEY:     cols =  255;     break;
  203.     }
  204.     *numofrows = rows;
  205.     *numofcols = cols;
  206. }
  207.  
  208.  
  209. /*============================| alterwindow |===============================*\
  210. Handles the move/resize/scroll window commands.
  211. \*==========================================================================*/
  212. void alterwindow(void)
  213. {
  214.     int rows, cols;
  215.  
  216.     if(!virtualflag) altermode=MOVEMODE;
  217.  
  218.     if(extkey) {
  219.         getsteps( &rows, &cols );
  220.         switch(altermode) {
  221.             case MOVEMODE:   movewindow    (rows, cols ); break;
  222.             case RESIZEMODE: vresizewindow (rows, cols ); break;
  223.             case SCROLLMODE: vscrollview   (rows, cols ); break;
  224.         }
  225.     } else
  226.     if(virtualflag) {
  227.         switch(toupper(key)) {
  228.             case 'M': altermode=MOVEMODE; break;
  229.             case 'R': altermode=RESIZEMODE; break;
  230.             case 'S': altermode=SCROLLMODE; break;
  231.         }
  232.     }
  233. }
  234.  
  235.  
  236. /*============================| createscreen |==============================*\
  237. \*==========================================================================*/
  238. void createscreen(void)
  239. {
  240.     prefer_multitask=1;
  241.     initwindow( YELLOW+BLACK_BG, 1, 0 );
  242.     setvirtualsize( 25, 80 );     /* to keep heap limited */
  243.     titleofs = 0;            /* place titles at extreme LEFT or RIGHT */
  244.     /* margins.top_margin=2; */
  245.     margins.bottom_margin=crt_rows-1;
  246.     /* margins.right_margin=79;
  247.     margins.left_margin=2; */
  248.     qfill( crt_rows, 1, 1, crt_cols, GREEN_BG, ' ' );
  249.     qwrite( crt_rows, 2, WHITE+GREEN_BG, "Alt:1-4" );
  250.     qwriteeos( BLACK+GREEN_BG, "-Window Num  " );
  251.     qwriteeos( WHITE+GREEN_BG, "ESC" );
  252.     qwriteeos( BLACK+GREEN_BG, "-Hide  " );
  253.     qwriteeos( WHITE+GREEN_BG, "F5" );
  254.     qwriteeos( BLACK+GREEN_BG, "-Zoom  " );
  255.     qwriteeos( WHITE+GREEN_BG, "F10" );
  256.     qwriteeos( BLACK+GREEN_BG, "-Quit  " );
  257.     initsteprates();
  258.     setwindowmodes( /* ZOOMMODE | */ CURSOROFFMODE | VIRTUALMODE );
  259.  
  260.     /* -- virtual window 1 -- */
  261.     makewindow( 1, 1, 20, 60, BLACK+BROWN_BG, BLACK+BROWN_BG, SINGLE_BORDER,
  262.                 WINDOW1 );
  263.     writetovirtual( tws.wsname );
  264.     titlewindow( TOP, LEFT, WHITE+BROWN_BG, "1 Virtual Window " );
  265.     for(i=0; i<25; i++) wwrite( i+1, 2, stra[i] );
  266.     vupdatewindow();
  267.  
  268.     /* -- virtual window 2 -- */
  269.     writetocrt();
  270.     makewindow( 6, 10, 16, 60, WHITE+GREEN_BG, WHITE+GREEN_BG, SINGLE_BORDER,
  271.                 WINDOW2 );
  272.     writetovirtual( tws.wsname );
  273.     titlewindow( TOP, LEFT, YELLOW+GREEN_BG, "2 Virtual Window  " );
  274.     for(i=0; i<25; i++) wwrite( i+1, 2, stra[i] );
  275.     vupdatewindow();
  276.  
  277.     /* -- virtual window 3 -- */
  278.     writetocrt();
  279.     makewindow( 11, 20, 14, 59, WHITE+BLUE_BG, WHITE+BLUE_BG, SINGLE_BORDER,
  280.                 WINDOW3 );
  281.     writetovirtual( tws.wsname );
  282.     titlewindow( TOP, LEFT, YELLOW+BLUE_BG, "3 Virtual Window  " );
  283.     for(i=0; i<25; i++) wwrite( i+1, 2, stra[i] );
  284.     vupdatewindow();
  285.  
  286.     /* -- fixed window 4 -- */
  287.     writetocrt();
  288.     setwindowmodes( CURSOROFFMODE );
  289.     makewindow( 7, 42, 17, 32, BLACK+LIGHTGRAY_BG, BLACK+LIGHTGRAY_BG,
  290.                 HDOUBLE_BORDER, WINDOW4 );
  291.     titlewindow( TOP, LEFT, SAMEATTR, "4" );
  292.     titlewindow( TOP, CENTER, SAMEATTR, " Fixed Window " );
  293.     wwritec( 1, "DYNAMIC UPDATING!!" );
  294.     wbrdrh( 2 );
  295.     wwritec( 3, "Instructions:" );
  296.     tws.wsline = SINGLE_BORDER;
  297.     wlineh( 4, 3, tws.wcols-4 );
  298.     wwrite( 5, 3, "ESC - Hide top window" );
  299.     wwrite( 6, 3, "F5  - Zoom virtual window" );
  300.     wwrite( 7, 3, "F10 - Quit" );
  301.     wwrite( 8, 3, "Alt:1-4 - Access window" );
  302.     wwrite( 9, 3, "With ScrollLock on:" );
  303.     wwrite(10, 5,   "R - Resize mode" );
  304.     wwrite(11, 5,   "S - Scroll mode" );
  305.     wwrite(12, 5,   "M - Move   mode" );
  306.     wwrite(13, 5,   "Then arrow keys." );
  307.     wwrite(14, 3, "Ctrl-NumLock to freeze." );
  308.     wwrite(15, 3, "Any other key to pause." );
  309.     wgotorc( tws.wrows, 1 );
  310.     changeborder( DOUBLE_BORDER );
  311. }
  312.  
  313.  
  314. void main(void)
  315. {
  316. /*  qsnow=0; */
  317.  
  318.     kbdidlefunc = kbdidle;          /* set hook for kbdidle routine! */
  319.     useint9handler( 1 );            /* set to 1 for solid keyboard action. */
  320.                                     /* use 0 for debugging. */
  321.     createscreen();
  322.     name=WINDOW1;
  323.  
  324.     do {
  325.         readkbd( &key, &extkey, &typematic );
  326.         if(scrollon()) alterwindow();
  327.         if(extkey) {
  328.             switch(key) {
  329.                 case ALT1:
  330.                 case ALT2:
  331.                 case ALT3:
  332.                 case ALT4:
  333.                     restoreborder();
  334.                     accesswindow( key-ALT1+1 );
  335.                     changeborder( DOUBLE_BORDER ); break;
  336.                 case F5KEY: vzoomwindow(); break;
  337.             }
  338.         } else {
  339.             switch(key) {
  340.                 case ESCKEY:
  341.                     hidewindow();
  342.                     changeborder( DOUBLE_BORDER ); break;
  343.             }
  344.         }
  345.     } while(!(extkey && (key==F10KEY)));
  346.  
  347.     accesswindow( WINDOW0 );
  348.     wclrscr();
  349.     setcursor( cursor_initial );
  350.     exit(0);
  351. }
  352.